package com.ruoyi.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.domain.Brand;
import com.ruoyi.mapper.BrandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.CommodityMapper;
import com.ruoyi.domain.Commodity;
import com.ruoyi.service.ICommodityService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 商品Service业务层处理
 *
 * @author ruoyi
 * @date 2023-08-07
 */
@Service
public class CommodityServiceImpl  extends ServiceImpl<CommodityMapper, Commodity>  implements ICommodityService
{
    @Resource
    private CommodityMapper commodityMapper;

    /**
     * 查询商品
     *
     * @param id 商品主键
     * @return 商品
     */
    @Override
    public Commodity selectCommodityById(Long id)
    {
        return commodityMapper.selectCommodityById(id);
    }

    /**
     * 查询商品列表
     *
     * @param commodity 商品
     * @return 商品
     */
    @Override
    public List<Commodity> selectCommodityList(Commodity commodity)
    {
        return commodityMapper.selectCommodityList(commodity);
    }

    /**
     * 新增商品
     *
     * @param commodity 商品
     * @return 结果
     */
    @Override
    public int insertCommodity(Commodity commodity)
    {
        commodity.setCreateTime(DateUtils.getNowDate());
        commodity.setCreateBy(ShiroUtils.getLoginName());
        return commodityMapper.insertCommodity(commodity);
    }

    /**
     * 修改商品
     *
     * @param commodity 商品
     * @return 结果
     */
    @Override
    public int updateCommodity(Commodity commodity)
    {
        return commodityMapper.updateCommodity(commodity);
    }

    /**
     * 批量删除商品
     *
     * @param ids 需要删除的商品主键
     * @return 结果
     */
    @Override
    public int deleteCommodityByIds(String ids)
    {
        return commodityMapper.deleteCommodityByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除商品信息
     *
     * @param id 商品主键
     * @return 结果
     */
    @Override
    public int deleteCommodityById(Long id)
    {
        return commodityMapper.deleteCommodityById(id);
    }
}
